package com.ruoyi.common.core.domain.entity;

import com.ruoyi.common.core.domain.BaseEntity;
import jakarta.persistence.*;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import java.io.Serial;
import java.util.ArrayList;
import java.util.List;

/**
 * 部门表 sys_dept
 *
 * @author ruoyi
 */
@EqualsAndHashCode(callSuper = true)
@Entity
@DynamicUpdate
@DynamicInsert
@Data
public class SysDept extends BaseEntity {
	@Serial
	private static final long serialVersionUID = 1L;

	/**
	 * 部门ID
	 */
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO, generator = "sys_dept_seq")
	@SequenceGenerator(name = "sys_dept_seq", initialValue = 1000)
	@Comment("部门id")
	private Long deptId;

	/**
	 * 父部门ID
	 */
	@ColumnDefault("0")
	@Comment("父部门id")
	private Long parentId;

	/**
	 * 祖级列表
	 */
	@Comment("祖级列表")
	@Column(length = 50)
	@ColumnDefault("''")
	private String ancestors;

	/**
	 * 部门名称
	 */
	@Comment("部门名称")
	@ColumnDefault("''")
	@Column(length = 50)
	@NotBlank(message = "部门名称不能为空")
	@Size(max = 30, message = "部门名称长度不能超过30个字符")
	private String deptName;

	/**
	 * 显示顺序
	 */
	@Comment("显示顺序")
	@ColumnDefault("0")
	@Column(length = 4)
	@NotNull(message = "显示顺序不能为空")
	private Integer orderNum;

	/**
	 * 负责人
	 */
	@Comment("负责人")
	@Column(length = 20)
	private String leader;

	/**
	 * 联系电话
	 */
	@Comment("联系电话")
	@Column(length = 11)
	@Size(max = 11, message = "联系电话长度不能超过11个字符")
	private String phone;

	/**
	 * 邮箱
	 */
	@Comment("邮箱")
	@Column(length = 50)
	@Email(message = "邮箱格式不正确")
	@Size(max = 50, message = "邮箱长度不能超过50个字符")
	private String email;

	/**
	 * 部门状态:0正常,1停用
	 */
	@Comment("部门状态:0正常,1停用")
	@ColumnDefault("'0'")
	@Column(length = 1)
	private String status;

	/**
	 * 删除标志（0代表存在 2代表删除）
	 */
	@Comment("删除标志（0代表存在 2代表删除）")
	@ColumnDefault("'0'")
	@Column(length = 1)
	private String delFlag;

	/**
	 * 父部门名称
	 */
	@Comment("父部门名称")
	@Transient
	private String parentName;

	/**
	 * 子部门
	 */
	@Comment("子部门")
	@Transient
	private List<SysDept> children = new ArrayList<>();

	@Override
	public String toString() {
		return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
				.append("deptId", getDeptId())
				.append("parentId", getParentId())
				.append("ancestors", getAncestors())
				.append("deptName", getDeptName())
				.append("orderNum", getOrderNum())
				.append("leader", getLeader())
				.append("phone", getPhone())
				.append("email", getEmail())
				.append("status", getStatus())
				.append("delFlag", getDelFlag())
				.append("createBy", getCreateBy())
				.append("createTime", getCreateTime())
				.append("updateBy", getUpdateBy())
				.append("updateTime", getUpdateTime())
				.toString();
	}


}
